var fileName, type, autoPlay, audioRepeat;
var self, contentHtml, sliceEffectType, transitionTime, div_number = 0;
var orient = 0;

function addMusicBg() {
    audioRepeatHtml = '';
    if(audioRepeat == true) {
        audioRepeatHtml = 'loop="loop"';
    }
    var autoPlayHtml = '';
    if(autoPlay == true) {
        autoPlayHtml = 'autoplay="autoplay"';
    }
    html = '<audio id="video_p" width="0" height="0" controls '+ audioRepeatHtml + ' ' + autoPlayHtml +'>';
    for(var i = 0; i<Object.keys(fileName).length; i++)
    {
        html = html + '<source src="'+fileName[i]+'" type="'+type[i]+'">';
        
    }
    html = html + '</audio>';
    $("#playBGMusic").html(html);
    $('#playBGMusic audio').each(function() {
          $(this)[0].play();          
    });
} 

function setBGM(fileName, type, autoPlay, audioRepeat){
    window.fileName = fileName;
    window.type = type;
    window.autoPlay = autoPlay; 
    window.audioRepeat = audioRepeat;
    
    addMusicBg();
}

function playBGM() {
    $('#playBGMusic audio').each(function() {
          $(this)[0].play();          
    });
}

function pauseBGM() {
    $('#playBGMusic audio').each(function() {
          $(this)[0].pause();         
    });
}

function pauseAllMusic(){
    $('audio, video').each(function() {
          $(this)[0].pause();     
    });
}

function playAllMusic(){
    $('audio, video').each(function() {
          $(this)[0].play();    
    });
}

function playContentVideo() {
    $("#main-content audio, #main-content video").each(function() {
        $(this)[0].play();        
    });
}
    
function setWebBG(link_image) {
    $("body").css("background", 'url('+link_image+')');
}

function getRandomInt (min, max) {
    return Math.floor(Math.random() * (max - min + 1)) + min;
}

function IsImageOk(img) {
    if (!img.complete) {
        return false;
    }

    if (typeof img.naturalWidth!= "undefined" && img.naturalWidth == 0) {
        return false;
    }

    return true;
}

function checkImages() {
    for (var i = 0; i < document.images.length; i++) {
        if (!IsImageOk(document.images[i])) {
            document.images[i].src = "/images/loaderror.jpg";
        }
    }
}

function setHTMLContent(contentHtml, sliceEffectType) {
    transition = Array(
        'cubeleft', 'cuberight', 'dissolve', 'fade', 'flipleft', 'flipright',
        'pop', 'swapleft', 'slidedown', 'slideright', 'slideup', 'slideleft'
    );
    
    div_id = '#next-content';
    
    if(div_number == 0) {
        div_id = '#next-content';
        div_number = 1;
    }
    else {
        div_id = '#prev-content';
        div_number = 0;
    }
    
    $(div_id).html(contentHtml);
    
    if(div_id == '#next-content')
        $('#prev-content').html('');
    else
        $('#next-content').html('');

    //resizeFrame();
        
    try{        
        jQT.goTo(div_id, sliceEffectType);
    }
    catch(err){
        jQT.goTo(div_id, sliceEffectType);
    }
}

function runSlide() {
    
}